<template>
    <div class="box">
        <biaoti title="首页"></biaoti>

        <van-pull-refresh v-model="loading" @refresh="onRefresh">
            <div class="doc" >
                <van-icon name="list-switch" @click="listFun()"/>
                <sousuo></sousuo>
                <p @click="loginFun()">登录</p>
            </div>


            <!-- <van-swipe :autoplay="3000" lazy-render>
            <van-swipe-item v-for="image in list" :key="image">
                <img :src="image.image_src" style="width: 100%;"/>
            </van-swipe-item>
        </van-swipe> -->
            <lunbo :list="list"></lunbo>
            <van-grid :border="false" :column-num="2">
                <van-grid-item v-for="(v, i) in user" :key="i" @click="editFun(v.goods_id)">
                    <van-image
                        :src="v.goods_small_logo ? v.goods_small_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg'" />
                    <p>{{ v.goods_name }}</p>
                </van-grid-item>
            </van-grid>
        </van-pull-refresh>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { swiperdataApi, searchApi } from '@/api/api';
import { showToast } from 'vant';
import biaoti from '@/components/biaoti.vue';
import sousuo from '@/components/sousuo.vue';
import lunbo from '@/components/lunbo.vue';
const images = [
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
];

let list = ref("")
const getlist = () => {
    swiperdataApi().then(res => {
        list.value = res.data.message
    })
}
getlist()

let user = ref("")
const userlist = () => {
    searchApi().then(res => {
        user.value = res.data.message.goods
    })
}
userlist()
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const route = useRoute()

const editFun = (goods_id) => {
    router.push({ path: '/detiel', query: { goods_id: goods_id } })
}


const loading = ref(false);
const onRefresh = () => {
    setTimeout(() => {
        showToast('刷新成功');
        loading.value = false;
        getlist()
        userlist()
    }, 1000);
};

const listFun=()=>{
    router.push('/home/list')
}


const loginFun=()=>{
    router.push('/login')
}
</script>

<style lang="scss" scoped>
.box {
    overflow: auto;
    .doc{
        display: flex;
        align-items: center;
    }
}
</style>